<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>课程计划修改</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="./css/x-admin.css" media="all">
</head>
<body>
	<div class="x-nav">
		<span class="layui-breadcrumb"> <a><cite>首页</cite></a> <a><cite>></cite></a> <a><cite>课程管理</cite></a> <a><cite>></cite></a>
			<a><cite>课程计划信息</cite></a> <a><cite>></cite></a> <a><cite>课程计划信息修改</cite></a>
		</span> <a class="layui-btn layui-btn-small"
			style="line-height: 1.6em; margin-top: 3px; float: right"
			href="javascript:location.replace(location.href);" title="刷新"><i
			class="layui-icon" style="line-height: 30px">ဂ</i></a>
	</div>
	<div class="x-body">
		<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
			<div class="layui-tab-content">
				<div class="layui-tab-item layui-show">
					<form class="layui-form layui-form-pane">
						<div class="layui-form-item">
							<label class="layui-form-label"> <span class='x-red'>*</span>课程计划号
							</label>
							<div class="layui-input-block">
								<input type="number" name="cpNo" id="cpNo"
									value="<%=request.getParameter("cpNo")%>" autocomplete="off"
									class="layui-input" readonly="readonly">
							</div>
						</div>

						<div class="layui-form-item">
							<label class="layui-form-label"> <span class='x-red'>*</span>课程号
							</label>
							<div class="layui-input-block">
								<input type="hidden" name="selectcourse" id="selectcourse" value="<%=request.getParameter("courseNo")%>">
								<select name="courseNo" id="courseNo" ></select>
							</div>
						</div>

						<div class="layui-form-item">
							<label class="layui-form-label"> <span class='x-red'>*</span>教员号
							</label>
							<div class="layui-input-block">
								<input type="hidden" name="selectteach" id="selectteach" value="<%=request.getParameter("teacherNo")%>">
								<select name="teacherNo" id="teacherNo" ></select>
							</div>
						</div>

						<div class="layui-form-item">
							<label class="layui-form-label"> <span class='x-red'>*</span>开始时间
							</label>
							<div class="layui-input-block">
								<input type="date" name="courseStart" id="courseStart"
									value="<%=request.getParameter("courseStart")%>"
									autocomplete="off" placeholder="" class="layui-input">
							</div>
						</div>
						
						<div class="layui-form-item">
							<label class="layui-form-label"> <span class='x-red'>*</span>结束时间
							</label>
							<div class="layui-input-block">
								<input type="date" name="courseEnd" id="courseEnd"
									value="<%=request.getParameter("courseEnd")%>"
									autocomplete="off" placeholder="" class="layui-input">
							</div>
						</div>

						<div class="layui-form-item">
							<label class="layui-form-label"> <span class='x-red'>*</span>上课人数
							</label>
							<div class="layui-input-block">
								<input type="number" name="courseNum" id="courseNum"
									value="<%=request.getParameter("courseNum")%>"
									autocomplete="off" placeholder="请输入数字" class="layui-input">
							</div>
						</div>

						<div class="layui-form-item">
							<label class="layui-form-label"> <span class='x-red'>*</span>上课地点
							</label>
							<div class="layui-input-block">
								<input type="text" name="coursePlace" id="coursePlace"
									value="<%=request.getParameter("coursePlace")%>"
									autocomplete="off" placeholder="请输入文字" class="layui-input">
							</div>
						</div>

						<div class="layui-form-item">
							<label class="layui-form-label"> <span class='x-red'>*</span>上课时间
							</label>
							<div class="layui-input-block">
								<input type="text" name="courseTime" id="courseTime"
									value="<%=request.getParameter("courseTime")%>"
									autocomplete="off" placeholder="格式为:8:00-16:00"
									class="layui-input">
							</div>
						</div>
						<%
							String s = request.getParameter("courseStatus");
							String c = "";
							if (s.equals("1")) {
								c = "招募中";
							} else if (s.equals("2")) {
								c = "开课中";
							} else if (s.equals("3")) {
								c = "已结课";
							} else if (s.equals("4")) {
								c = "已取消";
							} else {
								c = "已满员";
							}
						%>
						<div class="layui-form-item">
							<label class="layui-form-label"> <span class='x-red'>*</span>状态
							</label>
							<div class="layui-input-block">
								<input type="hidden" name="selectstatusid" id="selectstatusid" value="<%=s%>">
								<input type="hidden" name="selectstatus" id="selectstatus" value="<%=c%>">
								<select name="courseStatus" id="courseStatus"></select>
							</div>
						</div>
						<div class="layui-form-item">
							<button class="layui-btn" lay-submit="" lay-filter="upd">
								保存</button>
						</div>
					</form>
					<div style="height: 100px;"></div>
				</div>
			</div>
		</div>
	</div>
	<script src="layui/layui.js" charset="utf-8"></script>
	<script src="./js/x-layui.js" charset="utf-8"></script>
	<script src="./js/jquery-2.0.3.js" charset="utf-8"></script>
	<script>
	  	var selectcourse = $("#selectcourse").val();
	  	var selectteach = $("#selectteach").val();
		$(function() {
			$.get("CourseServlet?op=ajaxReq", function(data) {
				$("#courseNo").append(
						"<option value="+selectcourse+">"
								+ selectcourse + "</option>");
				$.each(data, function(index, course) {
					if(course.courseNo != selectcourse){
						$("#courseNo").append(
								"<option value="+course.courseNo+">"
										+ course.courseNo + "</option>");
					}
				});
			});
			$.get("TeachServlet?op=ajaxReq", function(data) {
				$("#teacherNo").append(
						"<option value="+selectteach+">"
								+ selectteach + "</option>");
				$.each(data, function(index, teacher) {
					if(teacher.teacherNo != selectteach){
						$("#teacherNo").append(
								"<option value="+teacher.teacherNo+">"
										+ teacher.teacherNo + "</option>");
					}
				});
			});
			
			
		});

		layui.use([ 'element', 'layer', 'form' ], function() {
			$ = layui.jquery;//jquery
			layer = layui.layer;//弹出层/
			form = layui.form;

			//监听提交
			form.on('submit(upd)', function(data) {
				var cpNo = $("#cpNo").val();
				var courseNo = $("#courseNo").val();
				var teacherNo = $("#teacherNo").val();
				var courseStart = $("input[name='courseStart']").val();
				var courseEnd = $("input[name='courseEnd']").val();
				var courseNum = $("input[name='courseNum']").val();
				var coursePlace = $("input[name='coursePlace']").val();
				var courseTime = $("input[name='courseTime']").val();
				var courseStatus = $("#courseStatus").val();

				if (courseStart == "") {
					layer.msg('开始时间不能为空', {
						icon : 5,
						time : 2000
					});
					return false;
				}
				if (courseEnd == "") {
					layer.msg('结束时间不能为空', {
						icon : 5,
						time : 2000
					});
					return false;
				}
				if (courseNum == "") {
					layer.msg('上课人数不能为空', {
						icon : 5,
						time : 2000
					});
					return false;
				}
				if (coursePlace == "") {
					layer.msg('上课地点不能为空', {
						icon : 5,
						time : 2000
					});
					return false;
				}
				if (courseTime == "") {
					layer.msg('上课时间不能为空', {
						icon : 5,
						time : 2000
					});
					return false;
				}

				$.ajax({
					type : "get",
					url : "CoursePlanServlet",
					data : {
						cpNo : cpNo,
						courseNo : courseNo,
						teacherNo : teacherNo,
						courseStart : courseStart,
						courseEnd : courseEnd,
						courseNum : courseNum,
						coursePlace : coursePlace,
						courseTime : courseTime,
						courseStatus : courseStatus,
						op : "upd"
					},
					dataType : "json",
					success : function(data) {
						if (data.code == 1) {
							layer.msg(data.msg, {
								icon : 6,
								time : 2000
							}, function() {
								window.parent.location.reload();//刷新父页面
								var index = parent.layer
										.getFrameIndex(window.name);
								parent.layer.close(index);//关闭子页面
							});
							return false;
						} else {
							layer.msg(data.msg, {
								icon : 5,
								time : 2000
							});
							return false;
						}
					}
				});
				return false;
			});
		})
	</script>
	<script type="text/javascript">
		var sta = ["招募中","开课中","已结课","已取消","已满员"];
	  	var selectstatusid = $("#selectstatusid").val();
	  	var selectstatus = $("#selectstatus").val();
		$(function() {
			$("#courseStatus").append("<option value="+selectstatusid+">"+ selectstatus + "</option>");
			for (var st = 0; st < 5 ; st++) {
				
				if((st+1) != selectstatusid ){
					console.log(sta[st]);
					$("#courseStatus").append("<option value="+(st+1)+">"+ sta[st] + "</option>");
				}
			}
		});
	</script>
</body>
</html>